<!DOCTYPE HTML>
<html>
<head>
	<?php
		include("include.php");
		
		$tags = tag::getAllTags();
		$userID = userHelper::getUserID();
	
		if(!empty($_POST['action']) && $_POST['action'] == 'new')
		{
			$name = mysql_real_escape_string($_POST['name']);
			$location = mysql_real_escape_string($_POST['location']);
			$host = mysql_real_escape_string($_POST['host']);
			$description = mysql_real_escape_string($_POST['description']);
			$link = mysql_real_escape_string($_POST['link']);
			$image = mysql_real_escape_string($_POST['image']);
			$start = mysql_real_escape_string($_POST['start']);
			$end = mysql_real_escape_string($_POST['end']);
			$tags = $_POST['tags'];
			//echo '<pre>'.print_r($tags, true).'</pre>'; die();
			
			eventClass::createNewEvent($userID, $name, $description, $location, $host, $link, $image, $start, $end);
			
			$eventID = eventClass::getEventIDByEverything($userID, $name, $description, $location, $host, $link, $image, $start, $end);
			
			foreach($tags as $key => $tagID)
			{
				eventClass::addTagToNewEvent($eventID, $tagID);
			}
		}
	?>
	
	<style>
		#content label{ display:inline-block;width:90px; }
		#content label.error{ width:200px; margin-left:95px; display:block; color:red; }
	</style>
	
</head>
<body>

<div class="container">
	<div id="header">
		<?php include("banner.php")?>
		
		<div id="login">
			<?php login::displayLoginDiv(); ?>
		</div>
		
		<div class="clear"></div>
		
		<div id="navigation">
			<?php include('navigation.php'); ?>
		</div>
	</div>
	
	<div class="clear"></div>
	
	<div id="body">
		<div id="content">
		
			<h1>New Event</h1>
				
			<?php 
			if(empty($_POST['action']))
			{ ?>
				<form id="createEventFrom" name="createEventFrom" method="post" action="newevent.php">
					<label for="name">Event Name:</label>
						<input id="name" type="text" class="text required" name="name"/>
						<br/>
					<label for="location">Location:</label>
						<input id="location" type="text" class="text required" name="location"/>
						<br/>
					<label for="host">Hosted By:</label>
						<input id="host" type="text" class="text required" name="host" />
						<br/>
					<label for="description" style="float:left; margin-right:4px;">Description:</label>
						<textarea id="description" class="text required" name="description" cols="65" rows="10"></textarea>
						<br/>
					<label for="start">Start Time:</label>
						<input id="start" type="text" class="text required" name="start" />
						<br/>
					<label for="end">End Time:</label>
						<input id="end" type="text" class="text required" name="end" />
						<br/>
					<label for="tags" style="float:left; margin-right:4px;">Tags:</label>
						<select name="tags[]" multiple="multiple" size="10" style="width:300px;" class="required">
							<?php foreach($tags as $ID => $name){ ?>
								<option value="<?php echo $ID; ?>"><?php echo $ID; ?> - <?php echo $name; ?></option>
							<?php } ?>
						</select>
						<span class="small">Press ctrl to select multiple tags.</span>
						<br/>
					<label for="image">Image URL:</label>
						<input id="image" type="text" class="text required" name="image" />
						<br/>
					<label for="link">Link:</label>
						<input id="link" type="text" class="text" name="link" />
						<br/>
					
					<br/>
					<input type="hidden" name="action" value="new" />
					<input type="submit" class="submit" value="Create Event">
				</form>
				
				<script>
					$("#createEventFrom").validate();
				</script>
			<?php }
			else 
			{ ?>
				<p>New Event has been saved</p>
				<p>Visit it <a href="event.php?eventID=<?php echo $eventID; ?>">Here</a></p>
			<?php } ?>
			
			
		</div>
		<div id="tags">
			<h1>Tags</h1>
			<?php tag::displayTagCloud(); ?>
		</div>
		
		<div id="fblike">
			<?php include "facebookLike.php"; ?>
        </div>
	
	</div>
	
	<div class="clear"></div>
	
	<div id="footer">
		<?php include("footer.php"); ?>
	</div>

</div>


</body>
</html>